<?php

namespace lvzmen\yii\cms\widgets\modal;

use Yii;
use yii\bootstrap\Html;
use yii\bootstrap\Modal;

/**
 * A menu imitate the sidebar of https://docs.docker.com/get-started/
 *
 * @note It's depend on bootstrap;
 *
 * @example :
 * ```php

 * ```
 * @author chenzhiwei <chenzhiweiwk@qq.com>
 * @date   2021/08/31
 */
class MyFormModal extends Modal
{
    public $body = "";
    public $modal = "";

    /**
     * Initializes the widget.
     */
    public function init()
    {
        if(is_null($this->getId(false))) {
            $this->setId("modal_" . uniqid());
        }
        $this->options["id"] = $this->options["id"] ?? $this->getId();
        $this->initOptions();
    }

    /**
     * Renders the widget.
     */
    public function run()
    {
        $this->registerPlugin('modal');

        $result = "";
        $result .= $this->renderToggleButton() . "\n";
        $result .= Html::beginTag('div', $this->options) . "\n";
        $result .= Html::beginTag('div', ['class' => 'modal-dialog ' . $this->size]) . "\n";
        $result .= Html::beginTag('div', ['class' => 'modal-content']) . "\n";
        $result .= $this->renderHeader() . "\n";
        $result .= $this->renderBodyBegin() . "\n";
        $result .= $this->body . "\n";
        $result .= "\n" . $this->renderBodyEnd();
        $result .= "\n" . $this->renderFooter();
        $result .= "\n" . Html::endTag('div'); // modal-content
        $result .= "\n" . Html::endTag('div'); // modal-dialog
        $result .= "\n" . Html::endTag('div');

        return $result;
    }
}
